package edu.ynu.MyProject.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.ynu.MyProject.common.entity.LogicEntity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;


@Getter
@Setter
@Entity
@Where(clause = "is_deleted = 0")
public class Data extends LogicEntity {

    @Column
    private String name;

    @Column
    private String timestamp;

    @Column
    private int dataType;

    @Column
    private Double value;

    @Column
    private String boxId;

    @Column
    private int status;

    @Column
    private int connState;

    @Column
    private String connStateTimestamp;

    @Lob
    @Column
    private byte[] imageData;

    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties("datas")
    private Equipment equipment;

    @JsonProperty("id")
    public void setEquipmentId(Long deviceId) {
        if (deviceId != null) {
            this.equipment = new Equipment();
            this.equipment.setId(deviceId);
        }
    }
}
